home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / mpfeel.lha / MPFeel / Plurals / mp_object.h < prev    next >
C/C++ Source or Header  |  1992-07-15  |  4KB  |  154 lines

  1. /*
  2.  *    Objects
  3.  *
  4.  *    Author:    S.C.Merrall
  5.  *
  6.  *    File:    mp_object.h
  7.  *
  8.  *    Contents:    
  9.  *
  10.  *    Description:    I am attempting to write this code is an object
  11.  *                      orientated fashion. Objects in the system are 
  12.  *                      always of the form make_OBJECT and these objects
  13.  *                      are accessed via functions from this file. They
  14.  *                      are all macros but this should give a nice 
  15.  *                      generic feel to it.
  16.  *
  17.  *    Change History:
  18.  *
  19.  *    Date   Name Comment
  20.  *    -------- ---- -------
  21.  *    29:01:91 SCM  Created
  22.  *    18:02:91 SCM  Proper Naming convention plus generic accessors
  23.  *    19:04:91 SCM  Added Dynamic creation of objects
  24.  *    19:04:91 SCM  Added new class MP_PluralHeap
  25.  *    19:04:91 SCM  Class MP_Type removed
  26.  *    27:05:91 SCM  Class MP_PluralHeap no longer an object
  27.  *    28:06:91 SCM  Combined free and type into 32 bit info field
  28.  *
  29.  */
  30.  
  31.  
  32. /* Object Verification On/Off Flag */
  33. /* ====== ============ ====== ==== */
  34.  
  35. #define OD_OBJECT_CHECK on
  36.  
  37.  
  38. /* Bit masks for info field */
  39. /* === ===== === ==== ===== */
  40.  
  41. #define OD_FREE_FLAG_MASK 0x00000001
  42. #define OD_TYPE_MASK      (~0x00000001)
  43.  
  44. #define OM_type(OBJECT) ((OBJECT->Generic.info) & OD_TYPE_MASK)
  45. #define OM_freep(OBJECT) (((OBJECT->Generic.info)&OD_FREE_FLAG_MASK)==OD_FREE_FLAG_MASK)
  46.  
  47.  
  48. /* Static/Dynamic Flag Identifiers */
  49. /* ============== ==== =========== =*/
  50.  
  51. #define OD_STATIC     0x00000000
  52. #define OD_DYNAMIC    0x70000000
  53.  
  54. /* NOTE: these values are `ORed' with the Type Identifier => 31 types only */
  55.  
  56. /* Unique Identifiers */
  57. /* ====== =========== */
  58.  
  59. #define OI_make       0x00000000
  60.  
  61. #define OI_MP_Context  0x00000002
  62.  
  63. #define OI_Generic    0xFFFFFFFF
  64.  
  65. /* Structure Common To All Objects And Definition Of Object */
  66. /* ========= ====== == === ======= === ========== == ====== */
  67.  
  68. #define OD_COMMON_STRUCTURE int info; int (*destructor)(); object (*constructor)()
  69.  
  70. typedef union OU_object *object;
  71.  
  72.  
  73. /* Headers Of Objects */
  74. /* ======= == ======= */
  75.  
  76. #include "MP_Context.h"
  77. #include "MP_PluralHeap.h"  /* WARNING: these are not objects at all */
  78.  
  79.  
  80. /* Definition Of Object Structure */
  81. /* ========== == ====== ========= */
  82.  
  83. /*struct Generic_ {
  84.   int info;                 
  85.   int (*destructor)();
  86.   Object (*constructor)();
  87. };
  88. */
  89.  
  90. struct Generic {OD_COMMON_STRUCTURE;};
  91.  
  92. union OU_object {
  93.   struct Generic     Generic;
  94.   struct MP_Context   MP_Context;
  95. /*  struct MP_PluralHeap MP_PluralHeap; */
  96. };
  97.  
  98.  
  99. /* Generic object functions */
  100. /* ======= ====== ========= */
  101.  
  102. #ifdef OD_OBJECT_CHECK
  103.  
  104. #define OF_destroy(OBJECT) (error(OBJECT,"OF_destroy",OI_Generic)->Generic.destructor)(OBJECT)
  105. #define OF_make(thing) (object)memcpy((char *)error((object *)malloc(sizeof(thing)),"OF_make",OI_make),(char *)&thing, sizeof(thing))
  106. #define OF_create(OBJECT) (OBJECT.constructor)
  107. #define OF_free(OBJECT) ((error(OBJECT,"OF_free",OI_Generic)->Generic.info)=(OBJECT->Generic.info)|OD_FREE_FLAG_MASK)
  108.  
  109.  
  110.  
  111. #else
  112.  
  113. #define OF_destroy(OBJECT) (OBJECT->Generic.destructor)(OBJECT)
  114. #define OF_make(thing) (object)memcpy((char *)malloc(sizeof(thing)),(char *)&thing, sizeof(thing))
  115. #define OF_create(OBJECT) (OBJECT.constructor)
  116. #define OF_free(OBJECT) ((OBJECT->Generic.info)=(OBJECT->Generic.info)&OD_FREE_FLAG_MASK)
  117.  
  118. #endif
  119.  
  120. #define OF_stack(CLASS,NAME) struct CLASS NAME/**/_; object NAME = (object) memcpy((char *)& NAME/**/_, (char *)& DOC_/**/CLASS , sizeof(DOC_/**/CLASS))
  121.  
  122.  
  123. /* Generic Object Accessor */
  124. /* ======= ====== ======== */
  125.  
  126. #ifdef OD_OBJECT_CHECK
  127.  
  128. #else
  129.  
  130. #endif
  131.  
  132.  
  133. /* Declaration of obejct checking function */
  134. /* =========== == ====== ======== ======== */
  135.  
  136. #ifdef __STDC__
  137.  
  138. extern object error( object, char *,int );
  139. extern object no_constructor( void );
  140.  
  141. #else
  142.  
  143. extern object error();
  144. extern object no_constructor();
  145.  
  146. #endif
  147.  
  148. #define null(X) ((X == NULL) ? exit(fprintf(dbg,"ERROR: NULL pointer in %s called from %s\n",dbg_fname,old_dbg_fname)) : X)
  149.  
  150.  
  151. /* Partial Generic object functions */
  152. /* ======= ======= ====== ========= */
  153.  
  154.